#!/usr/bin/env bash

func()
{
    G=200
    echo "$FUNCNAME:hello"
}

func2()
{
    shift 3
    echo $@

    for arg in $@
    do
        echo $arg
    done
}

func3_sub()
{
    a=500
    echo "$FUNCNAME: a=$a"
}

func3()
{
    local a=400
    echo "$FUNCNAME: local a=$a"
    func3_sub
    echo "$FUNCNAME: a=$a"
}

main()
{
    echo $G
    local a=$(func)    # 子空间中执行，不影响当前空间
    echo $G
    echo "=============================="

    func
    echo $G
    echo "=============================="

    func2 arg1 arg2 arg3 arg4 arg5
    echo "=============================="

    func3
    echo "FUNCNAME: a=$a"
    echo "=============================="
}

G=100

main $@
exit $?
